package com.trade.data.job;

import cn.hutool.core.date.StopWatch;
import com.trade.data.dto.CoinMarketDto;
import com.trade.data.manager.CoinMarketManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Component
@Slf4j
public class MarketDataScheduledJob {
    /*@Autowired
    CoinMarketManager coinMarketManager;

    // 每2分钟执行一次
    @Scheduled(fixedRate = 10 * 60 * 1000)
    @Async("taskExecutor")
    public void executeDayTask() {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        List<String> coin = new ArrayList<>();
        coin.addAll(coinMarketManager.getUsdtContracts());
        //coin.addAll(Stream.of("BTCUSDT,ETHUSDT,BNBUSDT,1000SATSUSDT,GMXUSDT,SOLUSDT".split(",")).collect(Collectors.toList()));
        List<String> period = new ArrayList<>();
        period.addAll(Stream.of("1d,3d".split(",")).collect(Collectors.toList()));
        for (String coinSingle : coin) {
            for(String periodSingle: period){
                CoinMarketDto coinMarketDto = new CoinMarketDto();
                coinMarketDto.setInterval(periodSingle);
                coinMarketDto.setSymbol(coinSingle);
                coinMarketManager.saveCoinQuotes(coinMarketDto);
            }
        }
        stopWatch.stop();
        log.info("executeDayTask single exec  stopWatch cost : {} ms  amount",stopWatch.getTotalTimeMillis());

    }
    @Scheduled(fixedRate = 10 * 60 * 1000)
    @Async("taskExecutor")
    public void executeHourTask() {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        List<String> coin = new ArrayList<>();
        coin.addAll(coinMarketManager.getUsdtContracts());
        //coin.addAll(Stream.of("BTCUSDT,ETHUSDT,BNBUSDT,1000SATSUSDT,GMXUSDT,SOLUSDT".split(",")).collect(Collectors.toList()));
        List<String> period = new ArrayList<>();
        period.addAll(Stream.of("1h,2h,4h,6h,8h,12h".split(",")).collect(Collectors.toList()));
        for (String coinSingle : coin) {
            for(String periodSingle: period){
                CoinMarketDto coinMarketDto = new CoinMarketDto();
                coinMarketDto.setInterval(periodSingle);
                coinMarketDto.setSymbol(coinSingle);
                coinMarketManager.saveCoinQuotes(coinMarketDto);
            }
        }
        stopWatch.stop();
        log.info("executeHourTask single exec stopWatch cost : {} ms  amount",stopWatch.getTotalTimeMillis());

    }
    @Scheduled(fixedRate = 2 * 60 * 1000)
    @Async("taskExecutor")
    public void executeMinutesTask() {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        List<String> coin = new ArrayList<>();
        coin.addAll(coinMarketManager.getUsdtContracts());
        //coin.addAll(Stream.of("BTCUSDT,ETHUSDT,BNBUSDT,1000SATSUSDT,GMXUSDT,SOLUSDT".split(",")).collect(Collectors.toList()));
        List<String> period = new ArrayList<>();
        period.addAll(Stream.of("1m,3m,5m,15m,30m".split(",")).collect(Collectors.toList()));
        for (String coinSingle : coin) {
            for(String periodSingle: period){
                CoinMarketDto coinMarketDto = new CoinMarketDto();
                coinMarketDto.setInterval(periodSingle);
                coinMarketDto.setSymbol(coinSingle);
                coinMarketManager.saveCoinQuotes(coinMarketDto);
            }
        }
        stopWatch.stop();
        log.info("executeMinutesTask single exec stopWatch cost : {} ms  amount",stopWatch.getTotalTimeMillis());

    }
    @Scheduled(fixedRate = 60 * 60 * 1000)
    @Async("taskExecutor")
    public void executeWeekAndMonthTask() {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        List<String> coin = new ArrayList<>();
        coin.addAll(coinMarketManager.getUsdtContracts());
        //coin.addAll(Stream.of("BTCUSDT,ETHUSDT,BNBUSDT,1000SATSUSDT,GMXUSDT,SOLUSDT".split(",")).collect(Collectors.toList()));
        List<String> period = new ArrayList<>();
        period.addAll(Stream.of("1w,1M".split(",")).collect(Collectors.toList()));
        for (String coinSingle : coin) {
            for(String periodSingle: period){
                CoinMarketDto coinMarketDto = new CoinMarketDto();
                coinMarketDto.setInterval(periodSingle);
                coinMarketDto.setSymbol(coinSingle);
                coinMarketManager.saveCoinQuotes(coinMarketDto);
            }
        }
        stopWatch.stop();
        log.info("single exec stopWatch cost : {} ms  amount",stopWatch.getTotalTimeMillis());

    }*/
}
